package com.neusoft.neumooc.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.core.common.BaseService;
import com.neusoft.core.common.exception.ServiceException;
import com.neusoft.neumooc.dao.BackMenuDAO;
import com.neusoft.neumooc.vo.BackMenuVO;

@Service
@Transactional
public class BackMenuServiceImpl extends BaseService implements BackMenuService {

    @Autowired
    private BackMenuDAO backMenuDAO;
    
    @Override
    public List<BackMenuVO> getAllMenus() throws ServiceException {
        try {
            return backMenuDAO.getAllMenus();
        } catch (Exception e) {
            log.error("获取所有菜单列表失败", e);
            throw new ServiceException("获取所有菜单列表失败", e);
        }
    }

    @Override
    public List<BackMenuVO> getParentMenus() throws ServiceException {
        try {
            return backMenuDAO.getParentMenus();
        } catch (Exception e) {
            log.error("获取一级菜单列表失败", e);
            throw new ServiceException("获取一级菜单列表失败", e);
        }
    }

    @Override
    public List<BackMenuVO> getChildMenus(String parentId) throws ServiceException {
        try {
            return backMenuDAO.getChildMenus(parentId);
        } catch (Exception e) {
            log.error("获取子菜单列表失败", e);
            throw new ServiceException("获取子菜单列表失败", e);
        }
    }

    @Override
    public boolean addMenu(BackMenuVO menu) throws ServiceException {
        try {
            return backMenuDAO.addMenu(menu);
        } catch (Exception e) {
            log.error("添加菜单失败", e);
            throw new ServiceException("添加菜单失败", e);
        }
    }

    @Override
    public boolean updateMenu(BackMenuVO menu) throws ServiceException {
        try {
            return backMenuDAO.updateMenu(menu);
        } catch (Exception e) {
            log.error("更新菜单失败", e);
            throw new ServiceException("更新菜单失败", e);
        }
    }

    @Override
    public boolean deleteMenu(String menuId) throws ServiceException {
        try {
            return backMenuDAO.deleteMenu(menuId);
        } catch (Exception e) {
            log.error("删除菜单失败", e);
            throw new ServiceException("删除菜单失败", e);
        }
    }

    @Override
    public BackMenuVO getMenuById(String menuId) throws ServiceException {
        try {
            return backMenuDAO.getMenuById(menuId);
        } catch (Exception e) {
            log.error("根据ID获取菜单失败", e);
            throw new ServiceException("根据ID获取菜单失败", e);
        }
    }
} 